package com.yiwenup.leetcode.site;

import com.yiwenup.leetcode.ListNode;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.site
 * @Author yiwenup
 * @Date 2024-12-14 22:08:43
 * @Description https://leetcode.cn/problems/swap-nodes-in-pairs/
 */
public class No0024 {
    public ListNode swapPairs(ListNode head) {
        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = head;
        ListNode cur = dummyHead;
        while(cur.next != null && cur.next.next != null) {
            ListNode tmp1 = cur.next;
            ListNode tmp2 = cur.next.next.next;
            cur.next = cur.next.next;
            cur.next.next = tmp1;
            tmp1.next = tmp2;

            cur = cur.next.next;
        }

        return dummyHead.next;
    }
}
